import { type IDomEditor, SlateElement, DomEditor } from "@wangeditor/editor";
import { h, VNode } from "snabbdom";
import { constant, AttachmentElement } from "./constant";
/**
 * 渲染“附件”元素到编辑器
 * @param elem 附件元素
 * @param children 元素子节点，void 元素可忽略
 * @param editor 编辑器实例
 * @returns vnode 节点（通过 snabbdom.js 的 h 函数生成）
 */
function renderAttachment(elem: SlateElement, children: VNode[] | null, editor: IDomEditor): VNode {
  const { value = "" } = elem as AttachmentElement;
  return h(
    "div",
    {
      style: { "justify-content": "center", display: "flex" }
    },
    [
      h(
        "div",
        {
          style: {
            display: "inline-block",
            width: "auto",
            border: "1px solid",
            "box-shadow": "rgb(43, 179, 241) 6px 6px 0px 0px",
            padding: "8px",
            "font-weight": "900"
          }
        },
        [h("strong", {}, [value])]
      )
    ]
  );
}
const renderElemConf = {
  type: constant.type,
  renderElem: renderAttachment
};

export default renderElemConf;
